package com.example.myactspringboot.Interceptor;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * @Author Zhouchb
 * @Create 2024-03-11 21:38
 * @Description
 */
public class MyFilter implements Filter {
     /*   @Override
        public void init(FilterConfig filterConfig) throws ServletException {

        }*/
        @Override
        public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
/*            HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
            HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
            StringBuffer urlBuffer = httpServletRequest.getRequestURL();
            System.out.println("UrlFilter中的urlBuffer = "+ urlBuffer.toString());
            Map<String, String[]> parameterMap = httpServletRequest.getParameterMap();
            for (String url : parameterMap.get("url")) {
                httpServletResponse.sendRedirect(url);
                return;
            }*/

 /*           if (urlBuffer.toString().contains("platform/work")) {
                //使用forward请求转发
                System.out.println("过滤器doFilter中调用,forward请求转发.");
                httpServletRequest.getRequestDispatcher("/fujian/shangban").forward(httpServletRequest, httpServletResponse);
                return;
            } else if (urlBuffer.toString().contains("platform/touzi")) {
                //使用sendRedirect请求转发
                System.out.println("过滤器doFilter中调用,sendRedirect请求转发.");
                String redirectUrl = "http://localhost:8080/platform/fujian/touzi?num=1024";
                httpServletResponse.sendRedirect(redirectUrl);
                return;
            }*/
            filterChain.doFilter(servletRequest, servletResponse);
        }
        @Override
        public void destroy() {

        }

}
